//获取指定名称的cookie的值
function getCookie(name){
	var arrStr = document.cookie.split(/\s*;\s*/);
	for(var i = 0;i < arrStr.length;i ++){
		var temp = arrStr[i].split(/\s*=\s*/);
		if(temp[0] == name) 
			return decodeURI(temp[1]);
	}
	return '';
}

//添加cookie
function setCookie(name,value,liveDays){
	var str = name + "=" + encodeURI(value);
	if(liveDays && liveDays >= 0){                               //为0时不设定过期时间，浏览器关闭时cookie自动消失
		var date = new Date();
		var ms = liveDays*3600*1000*24;
		date.setTime(date.getTime() + ms);
		str += "; expires=" + date.toGMTString();
	}
	document.cookie = str;
}

//删除cookie
function delCookie(name)
{
	document.cookie = name+"=;expires="+(new Date(0)).toGMTString();
}
